<?php
/*
Plugin Name: Author Box After Posts
Plugin URI: http://www.92app.com/wordpress-plugins/author-box-after-posts
Description:Adds an author box after your post contents.The box contains author's avatar,name,post count,site link,personal description and Email.
Version: 1.2
Author: Jeriff Cheng
Author URI: http://www.92app.com/
*/

/*
Copyright 2011  Jeriff Cheng(Email : hschengyongtao@gmail.com)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
*/
		/*
			Contents:
		1.Add Facebook,Google,Twitter to User Contact Fields
		2.Add CSS Style Sheet
		3.Output of the Author Box
		*/

################################################################
##### 1. Add Facebook,Google,Twitter to User Contact Fields#####
################################################################		
function add_twitter_contactmethod( $contactmethods ) {
  $contactmethods['twitter'] = 'Twitter';
  $contactmethods['facebook'] = 'Facebook';
  $contactmethods['google_profile'] = 'Google Profile';
  return $contactmethods;
}
add_filter('user_contactmethods','add_twitter_contactmethod',10,1);

################################################################
######################### 2.Add CSS Style Sheet#################
################################################################	
function add_authorbox_css() {
    ?>
<link rel="stylesheet" href="<?php echo get_option('siteurl') . '/' . PLUGINDIR . '/' . dirname(plugin_basename (__FILE__))?>/authorboxafterposts.css" type="text/css" media="screen" />
    <?php
}
add_action(wp_head,add_authorbox_css,1);

################################################################
############### 3.Output of the Author Box#######################
################################################################
add_filter('the_content', 'add_author_box');
function add_author_box($content) {

	//Define the Main Part of Author Box
	$author_box='
	<div class="author_info">
	<h4>This post was written by </h4>
	<p><span class="author_photo">'.get_avatar(get_the_author_id() ).'</span><a rel="nofollow" href="'.get_the_author_meta( 'user_url' ).'">'.get_the_author_meta('display_name').'</a> &ndash; who has written <a rel="author" href="'.get_author_posts_url(get_the_author_meta( 'ID' )).'">'. get_the_author_posts().'</a> posts on <a href="'.get_bloginfo("home").'">'.get_bloginfo("name").'</a>.<br>'.get_the_author_description().'</p>
	<p class="author_email">
	<a href="mailto:'.get_the_author_email().'" title="Send an Email to the Author of this Post">Email</a>
	';
	
	//Fetch the User Social Contact Infomation
	$twitter = get_the_author_meta( 'twitter' );
	$facebook = get_the_author_meta( 'facebook' );
	$google_profile = get_the_author_meta( 'google_profile' );
	
	if($google_profile){
	$display_google_profile='&nbsp;&#8226;&nbsp;<a title="My Google +" rel="me nofollow" href="' . esc_url($google_profile) . '" target="_blank">Google +</a>';
	}
	if($facebook){
	$display_facebook_profile='&nbsp;&#8226;&nbsp;<a title="My facebook" rel="me nofollow" href="' . esc_url($facebook) . '" target="_blank">Facebook </a>';
	}
	if($twitter){	
	$display_twitter_profile='&nbsp;&#8226;&nbsp;<a title="My Twitter" rel="me nofollow" href="' . esc_url($twitter) . '" target="_blank">Twitter</a>';
	}
	
	//Dynamic Output of the Author Box (Show Info you've set)
	if(is_single()) {
	$content.= ($author_box.$display_google_profile.$display_facebook_profile.$display_twitter_profile.'</p></div>');
    }
    return $content;
}